//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.UIDesigner.Monitor
{
    using System.ComponentModel;
    using System;
    using System.Globalization;

    /// <summary>
    /// Model for monitor's workflow parameters Tab.
    /// </summary>
    public class WorkflowOutputProperty : INotifyPropertyChanged
    {
        /// <summary>
        /// Display Name of the workflow outputs.
        /// </summary>
        private string displayName;

        /// <summary>
        /// Name of the activity which generated the Data product.
        /// </summary>
        private string activityName;

        /// <summary>
        /// Name of the parameter which generated the Data product.
        /// </summary>
        private string parameterName;

        /// <summary>
        /// Name of the Data product.
        /// </summary>
        private string dataproductName;

        /// <summary>
        /// Actual data product Item.
        /// </summary>
        private DataProductItem data;

        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        /// <value>The display name.</value>
        public string DisplayName
        {
            get { return this.displayName; }
            set
            {
                if (this.displayName != value)
                {
                    this.displayName = value;
                    this.OnNotifyPropertyChanged("DisplayName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the name of the activity.
        /// </summary>
        /// <value>The name of the activity.</value>
        public string ActivityName
        {
            get { return this.activityName; }
            set
            {
                if (this.activityName != value)
                {
                    this.activityName = value;
                    this.OnNotifyPropertyChanged("ActivityName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the name of the parameter.
        /// </summary>
        /// <value>The name of the parameter.</value>
        public string ParameterName
        {
            get { return this.parameterName; }
            set
            {
                if (this.parameterName != value)
                {
                    this.parameterName = value;
                    this.OnNotifyPropertyChanged("ParameterName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the name of the dataproduct.
        /// </summary>
        /// <value>The name of the dataproduct.</value>
        public string DataProductName
        {
            get { return this.dataproductName; }
            set
            {
                if (this.dataproductName != value)
                {
                    this.dataproductName = value;
                    this.OnNotifyPropertyChanged("DataproductName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the data.
        /// </summary>
        /// <value>The data.</value>
        public DataProductItem Data
        {
            get { return this.data; }
            set
            {
                this.data = value;
                this.OnNotifyPropertyChanged("Data");
            }
        }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public Guid Id { get; set; }

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            string overiddenString = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}", this.ActivityName, this.ParameterName, this.DataProductName);
            if (string.IsNullOrEmpty(overiddenString))
            {
                return base.ToString();
            }
            else
            {
                return overiddenString;
            }
        }

        /// <summary>
        /// Called when [notify property changed].
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        private void OnNotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
